package com.wzdigit.wms.wms.controller.basic;

import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.common.utils.ValidatorUtil;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.basic.client.request.basic.CreateUpdateListZoneAttrRequest;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.basic.client.response.basic.ZoneAttrResponse;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.service.basic.ZoneAttrService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 库区属性 前端控制器
 * @author yangdongjie
 * @ZoneAttrController.java
 * @2020年12月31日下午5:56:27
 */
@RestController
@Api(tags = "库区属性")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class ZoneAttrController {

    @Autowired
    private ZoneAttrService zoneAttrService;

    private static final String REQUEST_MODEL = "/zone/attr";

    /**
     * 查询库区属性列表
     * @param zoneId
     * @param pager
     * @param servletRequest
     * @param servletResponse
     * @return
     */
    @ApiOperation(value = "查询库区属性列表",notes = "查询库区属性列表")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/searchZoneAttr")
    public <T> PagerInfo<List<ZoneAttrResponse>> searchZoneAttr(
    		@ApiParam(value = "库区ID", required = true) 
    		@RequestParam Integer zoneId, 
    		Pager<T> pager, 
    		HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return zoneAttrService.searchZoneAttr(zoneId, pager);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }
    
    
    /**
     * 批量新增/修改/删除 库位属性
     * @param <T>
     * @param dto
     * @param bindingResult
     * @param servletRequest
     * @param servletResponse
     * @return
     */
	@ApiOperation(value = "批量新增/修改/删除 库位属性",notes = "批量新增/修改/删除 库位属性")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @PostMapping(value = REQUEST_MODEL + "/createUpdateListZoneAttr")
    public <T> Result<T> createUpdateListZoneAttr(
    		@RequestBody @Valid CreateUpdateListZoneAttrRequest dto, 
    		BindingResult bindingResult, 
    		HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
	        ValidatorUtil.validator(bindingResult);
            return zoneAttrService.createUpdateListZoneAttr(dto, servletRequest);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }
	
    /**
     * 创建库区属性
     * @param dto
     * @param bindingResult
     * @param servletRequest
     * @param servletResponse
     * @return
     *//*
    @ApiOperation(value = "创建库区属性",notes = "创建库区属性")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @PostMapping(value = REQUEST_MODEL + "/createZoneAttr")
    public ZoneAttrResponse createZoneAttr(
    		@RequestBody @Valid CreateZoneAttrRequest dto, 
    		BindingResult bindingResult, 
    		HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
	    	ValidatorUtil.validator(bindingResult);
            return zoneAttrService.createZoneAttr(dto, servletRequest);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }
    
    *//**
     * 修改库区属性
     * @param dto
     * @param bindingResult
     * @param servletRequest
     * @param servletResponse
     * @return
     *//*
    @ApiOperation(value = "修改库区属性",notes = "修改库区属性")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @PutMapping(value = REQUEST_MODEL + "/updateZoneAttr")
    public ZoneAttrResponse updateZoneAttr(
    		@RequestBody @Valid UpdateZoneAttrRequest dto, 
    		BindingResult bindingResult, 
    		HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
	    	ValidatorUtil.validator(bindingResult);
            return zoneAttrService.updateZoneAttr(dto, servletRequest);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }
    
    *//**
     * 删除库区属性
     * @param whsAttrId
     * @param servletRequest
     * @param servletResponse
     * @return
     *//*
    @ApiOperation(value = "删除库区属性",notes = "删除库区属性")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @DeleteMapping(value = REQUEST_MODEL + "/deleteZoneAttr")
    public <T> Result<T> deleteZoneAttr(
    		@ApiParam(value = "库区属性ID", required = true) 
    		@RequestParam Integer zoneAttrId, 
    		HttpServletRequest servletRequest, 
            HttpServletResponse servletResponse) {
        try {
            return zoneAttrService.deleteZoneAttr(zoneAttrId);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }*/
}
